package com.ftg.elvis.mapper;

import com.ftg.elvis.pojo.Comment;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface AdminCommentMapper {

	@Select("select c.cid, c.comment, c.state, c.reply, c.user, c.star, b.bname, b.blogo, c.comtime from comment c , brand b where c.bid = b.bid " +
			"and comment like concat('%', #{arg2}, '%') and state like concat('%', #{arg4}, '%') and b.bname like concat('%', #{arg3}, '%') order by c.comtime desc limit #{arg0}, #{arg1}")
	List<Comment> showAll(int page, int limit, String comment, String bname, String state);

	@Select("select count(*) from comment c , brand b where c.bid = b.bid " +
			"and comment like concat('%', #{arg0}, '%') and state like concat('%', #{arg2}, '%')  and b.bname like concat('%', #{arg1}, '%')")
	int getCount(String comment, String bname, String state);

	@Delete("delete from comment where cid = #{cid}")
	int delete(String cid);

	@Update("update comment set reply = #{arg1}, state = '已回复' where cid = #{arg0}")
	int reply(String cid, String reply);
}
